package libra.sentinelTest.controller;

import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Sentinel - Degrade降级测试Controller
 */
@RestController
@RequestMapping("degrade")
public class DegradeController {
	String from = getClass().getSimpleName();
	
	/************************** 慢比例调用测试 ******************************/
	@RequestMapping("testSlowRequestRatio")
	public Object testSlowRequestRatio( HttpServletResponse resp ) throws Exception {
		Thread.sleep(100);
		return Map.of("from", from, "method", "testSlowRequestRatio", "sleep", 100);
	}
	
	
	/************************** 异常比例测试 ******************************/
	@RequestMapping("testErrorRatio")
	public Object testErrorRatio() {
		int i = 1/0;
		return Map.of("from", from, "method", "testErrorRatio");
	}
	
	
	/************************** 异常数测试 ******************************/
	@RequestMapping("testErrorCount")
	public Object testErrorCount() {
		int i = 1/0;
		return Map.of("from", from, "method", "testErrorCount");
	}
}
